from django.db import models
from django.utils import timezone
# Create your models here.

class TyphoonBasicInfo(models.Model):
    TYPOON_STATUS_CHOICES = [
        ('stop', 'Stop'),
        ('occur ', 'Occur '),
    ]
    Typhoon_Id = models.CharField("台风编号", max_length=255, unique=True)
    Typhoon_CName = models.CharField("中文名", max_length=255, null=True)
    Typhoon_EName = models.CharField("英文名", max_length=255, null=True)
    Typhoon_OnsetTime = models.DateTimeField("开始时间", default=timezone.now, null=True, blank=True)
    Typhoon_EndTime = models.DateTimeField("停止时间", default=timezone.now, null=True, blank=True)
    Typhoon_StopOrNot = models.CharField("是否停止", max_length=255, choices=TYPOON_STATUS_CHOICES,default='Stopped')

    def __str__(self):
        return f"台风名称: {self.Typhoon_CName or self.Typhoon_EName}({self.Typhoon_Id})"

class TyphoonLocationInfo(models.Model):
    Typhoon_Id = models.CharField("台风编号", max_length=255)
    Typhoon_PathId = models.CharField("路径编号", max_length=255, unique=True)
    Typhoon_CurrentTime = models.DateTimeField("当前路径时间", default=timezone.now)
    Typhoon_Longitude = models.FloatField("经度")
    Typhoon_Latitude = models.FloatField("纬度")

    class Meta:
        unique_together = ('Typhoon_Id', 'Typhoon_PathId')  # 保证 Typhoon_Id 和 Typhoon_PathId 组合唯一

    def __str__(self):
        return (f"台风路径编号: {self.Typhoon_PathId} - 路径时间: {self.Typhoon_CurrentTime}- "
                f"经度:{self.Typhoon_Longitude}- 纬度:{self.Typhoon_Latitude}")

class TyphoonGradeInfo(models.Model):
    INTENSITY_CHOICES = [
        ('热带低压(TD)', '热带低压'),
        ('热带风暴(TS)', '热带风暴'),
        ('强热带风暴(STS)', '强热带风暴'),
        ('台风(TY)', '台风'),
        ('强台风(STY)', '强台风'),
        ('超强台风(Super TY)', '超强台风')
    ]
    Typhoon_PathId = models.CharField("路径编号", max_length=255, unique=True)
    Typhoon_Intensity = models.CharField("台风强度", max_length=255, null=True, choices=INTENSITY_CHOICES)
    Typhoon_Level = models.PositiveIntegerField("台风等级", null=True)
    Typhoon_WindSpeed = models.IntegerField("风速", null=True)
    Typhoon_Pressure = models.IntegerField("压强", null=True)

    class Meta:
        verbose_name = 'Typhoon Grade Info'
        verbose_name_plural = 'Typhoon Grade Infos'

    def __str__(self):
        return f"台风路径编号: {self.Typhoon_PathId} - 等级: {self.Typhoon_Level} - 强度: {self.Typhoon_Intensity}"

